package com.qiyue.admin.biz.base;

import com.ace.cache.annotation.Cache;
import com.qiyue.admin.constant.RedisConstant;
import com.qiyue.admin.entity.base.group.GroupType;
import com.qiyue.admin.repository.base.group.GroupTypeRepsitory;
import com.qiyue.common.biz.BaseBiz;
import org.springframework.stereotype.Service;

import javax.persistence.Query;
import javax.transaction.Transactional;

/**
 * Created by y747718944 on 2018/2/7
 */
@Service
@Transactional(rollbackOn = Exception.class)
public class GroupTypeBiz extends BaseBiz<GroupTypeRepsitory,GroupType,Long> {

    /**
     * 获取 该用户的权限分组id
     *  是否缓存  缓存 5分钟
     * @param userId
     * @return
     */
    @Cache(key = RedisConstant.PERMISSION_GROUP+"userId:{1}" , expire = 5)
    public Object[] getGroupIdByUserId(String userId){
        String sql="select group_id from base_group_member where user_id = ?1 union select group_id from base_group_leader where user_id = ?1 ";
        Query query= this.entityManager.createNativeQuery(sql);
        query.setParameter("1",userId);
        return  query.getResultList().toArray();
    }
}
